package com.example.im.fragment;

import android.os.Bundle;
import android.view.View;

import androidx.recyclerview.widget.LinearLayoutManager;

import com.example.common.base.AbsFragment;
import com.example.im.R;
import com.example.im.adapter.ConversationAdapter;
import com.example.im.databinding.FragMainConversationBinding;
import com.example.im.utils.MessageUtils;
import com.example.im.utils.RouterUtils;
import com.tencent.imsdk.v2.V2TIMConversation;

import java.util.List;

public class ImConversationFragment extends AbsFragment<FragMainConversationBinding> {

    private List<V2TIMConversation> conversations;
    private ConversationAdapter mAdapter;

    public static ImConversationFragment getInstance()  {
        ImConversationFragment fragment = new ImConversationFragment();
        return fragment;
    }

    @Override
    protected void init(Bundle savedInstanceState) {
        initConversation();
        MessageUtils.getInstance().getConversationList(0, 100, data -> {
            if (data == null) {
                return;
            }
            conversations = data.getConversationList();
            mBinding.rvConversation.setLayoutManager(new LinearLayoutManager(mContext));
            mAdapter = new ConversationAdapter(conversations);
            mAdapter.setOnItemClickListener((adapter1, view, position) -> {
                RouterUtils.jumpIMChat(conversations.get(position).getUserID(),conversations.get(position).getShowName());
            });
            mBinding.rvConversation.setAdapter(mAdapter);
        });
    }

    private void initConversation() {

    }

    @Override
    protected void initView(View view) {

    }

    @Override
    protected void initListener() {

    }

    @Override
    protected int getLayoutId() {
        return R.layout.frag_main_conversation;
    }

    @Override
    protected void onRefresh() {

    }
}
